﻿<UserControl x:Class="Tanmia.Warehouse.Presentation.Scenarios.ItemUnitEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:c="clr-namespace:Tanmia.Warehouse.Presentation.Scenarios"
             xmlns:trace="clr-namespace:System.Diagnostics;assembly=WindowsBase"
             xmlns:basis="clr-namespace:Tanmia.Basis.WPF.Controls;assembly=Tanmia.Basis">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="80" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="80" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <Label Content="المادة: " Grid.Column="0" Grid.Row="0" />
        <TextBox Text="{Binding Path=Entity.Name}" IsReadOnly="True" Grid.Column="1" Grid.Row="0" />
        
        <Label Grid.Column="2" Grid.Row="0" Grid.ColumnSpan="2" Content="وحدات القياس" FontFamily="Sakkal Majalla" FontSize="18" FontWeight="Bold" FlowDirection="RightToLeft" />
        <DataGrid CanUserAddRows="True" CanUserDeleteRows="True" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="4" ItemsSource="{Binding Path=Entity.ItemUnitCollection}" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="الوحدة الأساسية">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Padding="5,0" Text="{Binding Path=BaseUnit.UnitName}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type c:ItemUnitEditor}}, Path=DataContext.BaseUnits}" Style="{x:Null}"
                                      DisplayMemberPath="UnitName" SelectedItem="{Binding Path=BaseUnit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                
                <DataGridTextColumn Header="معامل الضرب" Binding="{Binding Path=Scale, UpdateSourceTrigger=PropertyChanged}" />
                <DataGridTemplateColumn Header="الوحدة الجديدة">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Unit.UnitName}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type c:ItemUnitEditor}}, Path=DataContext.Units}" Style="{x:Null}"
                                      DisplayMemberPath="UnitName" SelectedItem="{Binding Path=Unit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</UserControl>
